﻿
$(function() {
    JSUtility.url = '../../Handler/AjaxHandle.ashx';
    JSUtility.param = { AssemblyName: "OA.Bll.Reimbursement", ClassName: "OA.Bll.Reimbursement.ReimbursementPresenter", Method: "Search", Options: {} };
    top.autoResize({ dataGrid: '#Grid', callback: InitReimbursementlist });
    
    JSHelper.combotreeProject('ProjectNum', "../Handler/AjaxProjectTreeHandle.ashx", 185);

    $("#CostType").combobox({
        onChange: InitCostSubjectData //function(newValue, oldValue) {
        //            var param = { AssemblyName: "OA.Bll.Reimbursement", ClassName: "OA.Bll.Reimbursement.ReimbursementDictionaryPresenter", Method: "SearchComboboxData", Options: {} };
        //            param.Options["CostType"] = newValue;
        //            $.ajax({
        //                type: "post",
        //                url: JSUtility.url,
        //                data: $.toJSON(param),
        //                dataType: "json",
        //                success: function(data) {
        //                    $("#CostSubject").combobox({
        //                        data: data,
        //                        textField: 'text',
        //                        valueField: 'text'
        //                    });
        //                }
        //            });
        //}
    });
   InitCostSubjectData();

    JSUtility.window_edit = $('#div_search').window({
        modal: true,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        title: "报销查询",
        closable: true,
        width: 560,
        //        height: 680,
        closed: true,
        onOpen: function() {
            $('#div_search').parent().css("left", "10%");
            $('#div_search').parent().next().css("left", "10%");
            $('#div_search').parent().next().css("top", "10%");
            $('#div_search').parent().css("top", "10%");
        }
    });
//    JSUtility.window_edit_form = $("#div_search > form");
//    JSUtility.window_edit_title = "报销查询";

    $("#btnSearch").bind("click", function() {
        $("#div_search").window("open");
    });

    $("#btnAdd").bind("click", function() {
        self.parent.addTab("报销支出", "../../Reimbursement/AddReimbursement.htm?type=add", "icon-sys");
    });
    $("#btnDel").click(JSUtility.del);
    $("#btnEdit").bind("click", function() {
        var rows = $("#Grid").datagrid('getSelections');
        var num = rows.length;
        if (num == 0) {
            $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
            return;
        } else {
            self.parent.addTab("报销支出", "../../Reimbursement/AddReimbursement.htm?type=edit&ReimbursementId=" + rows[0].Id, "icon-edit");
        }
    });
  
});

var SearchParam = { AssemblyName: "OA.Bll.Reimbursement", ClassName: "OA.Bll.Reimbursement.ReimbursementDictionaryPresenter", Method: "SearchComboboxData", Options: {} };
function SearchReimburesment() {
    //JSUtility.search();
    var items = $("#div_search > form").serializeArray();
    // JSUtility.param.Options = {};    
    $.each(items, function(i, item) {
        JSUtility.param.Options[item.name] = item.value;
    });

    $("#Grid").datagrid({ method: "post", queryParams: { "json": $.toJSON(JSUtility.param) }, url: JSUtility.url });
    $("#Grid").datagrid('options').pageNumber = 1;    
    $("#div_search").window('close');
    $("#div_search > form").form("clear");
}


function InitCostSubjectData() {

    var param = { AssemblyName: "OA.Bll.Reimbursement", ClassName: "OA.Bll.Reimbursement.ReimbursementDictionaryPresenter", Method: "SearchComboboxData", Options: {} };
    param.Options["CostType"] = $("#CostType").combobox("getText");
    $.ajax({
        type: "post",
        url: JSUtility.url,
        data: $.toJSON(param),
        dataType: "json",
        success: function(data) {
            $("#CostSubject").combobox({
                data: data,
                textField: 'text',
                valueField: 'text'
            });
        }
    });
}

function InitReimbursementlist(op, method, size) {
    // var p = JSUtility.param;
    //p.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        fitColumns: true,
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        striped: true,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        url: JSUtility.url,
        singleselect: true
    });
}